|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.ObjectcontrolP5.ControllerGroup
controlP5.ControlGroup
controlP5.ListBox
public class ListBox
scrollList, a list of selectable and scrollable items.
/**
* ControlP5 ListBox
* listBox operates the same way as a scrollList, but
* is optimized for many items (1000+). using a listBox
* over a scrollList is recommended
* by andreas schlegel, 2009
*/
import controlP5.*;
ControlP5 controlP5;
ListBox l;
int cnt = 0;
void setup() {
size(400,400);
frameRate(30);
controlP5 = new ControlP5(this);
l = controlP5.addListBox("myList",100,100,120,120);
l.setItemHeight(15);
l.setBarHeight(15);
l.captionLabel().toUpperCase(true);
l.captionLabel().set("something else");
l.captionLabel().style().marginTop = 3;
l.valueLabel().style().marginTop = 3; // the +/- sign
//l.setBackgroundColor(color(100,0,0));
for(int i=0;i<80;i++) {
l.addItem("item "+i,i);
}
l.setColorBackground(color(255,128));
l.setColorActive(color(0,0,255,128));
}
void keyPressed() {
if(key=='1') {
// set the height of a listBox should alwyays be a multiple of itemHeight
l.setHeight(210);
}
else if(key=='2') {
// set the height of a listBox should alwyays be a multiple of itemHeight
l.setHeight(120);
}
else if(key=='i') {
// set the height of a listBoxItem, should alwyays be a fraction of the listBox
l.setItemHeight(30);
}
else if(key=='u') {
// set the height of a listBoxItem, should alwyays be a fraction of the listBox
l.setItemHeight(10);
l.setBackgroundColor(color(100,0,0));
}
else if(key=='a') {
int n = (int)(random(100000));
l.addItem("item "+n, n);
}
else if(key=='d') {
l.removeItem("item "+cnt);
cnt++;
}
}
void controlEvent(ControlEvent theEvent) {
// ListBox is if type ControlGroup.
// 1 controlEvent will be executed, where the event
// originates from a ControlGroup. therefore
// you need to check the Event with
// if (theEvent.isGroup())
// to avoid an error message from controlP5.
if (theEvent.isGroup()) {
// an event from a group e.g. scrollList
println(theEvent.group().value()+" from "+theEvent.group());
}
}
void draw() {
background(128);
// scroll the scroll List according to the mouseX position
// when holding down SPACE.
if(keyPressed && key==' ') {
//l.scroll(mouseX/((float)width)); // scroll taks values between 0 and 1
}
if(keyPressed && key==' ') {
l.setWidth(mouseX);
}
}
| Field Summary |
|---|
| Fields inherited from interface controlP5.ControlP5Constants |
|---|
acceptClassList, ACTIVE, ALT, ARC, ARRAY, BACKSPACE, BOOLEAN, BOTTOM, CENTER, CONTROL, controlEventClass, CUSTOM, DECREASE, DEFAULT, DELETE, DOWN, ELLIPSE, ENTER, ESCAPE, EVENT, eventMethod, FIELD, FLOAT, HALF_PI, HIDE, HIGHLIGHT, HORIZONTAL, IMAGE, INCREASE, INTEGER, INVALID, KEYCONTROL, LEFT, LINE, LOAD, MENU, METHOD, MOVE, OVER, PI, PRESSED, PRINT, RELEASE, RESET, RIGHT, SAVE, SHIFT, SPRITE, STRING, SWITCH, SWITCH_BACK, SWITCH_FORE, TAB, TOP, TWO_PI, UP, VERBOSE, VERTICAL |
| Method Summary | |
|---|---|
void |
actAsPulldownMenu(boolean theValue)
Enable a ListBox to act as a pulldown menu. |
ListBoxItem |
addItem(java.lang.String theName,
int theValue)
Adds an item to the ListBox. |
void |
addToXMLElement(ControlP5XMLElement theElement)
|
void |
clear()
remove all items from a list box |
void |
controlEvent(ControlEvent theEvent)
ControlListener is an interface that can be implemented by a custom class. |
void |
hideScrollbar()
hide the scrollbar. |
boolean |
isScrollbarVisible()
check if the scrollbar is visible. |
ListBoxItem |
item(int theIndex)
returns a listBoxItem by index in the list of items. |
ListBoxItem |
item(java.lang.String theItemName)
TODO faulty returns a listBoxItem by name. |
void |
removeItem(java.lang.String theItemName)
Removes an item from the ListBox using the unique name of the item given when added to the list. |
void |
scroll(float theValue)
scroll the scrollList remotely. |
void |
setColorActive(int theColor)
set the color for the group when active. |
void |
setColorBackground(int theColor)
set the background color of the group. |
void |
setColorForeground(int theColor)
set the foreground color of the group. |
void |
setColorLabel(int theColor)
set the color of the text label of the group. |
void |
setColorValue(int theColor)
set the color of the value label. |
ListBox |
setHeight(int theHeight)
set the height of the list box. |
void |
setItemHeight(int theHeight)
set the height of list box items. |
ListBox |
setWidth(int theWidth)
|
void |
showScrollbar()
show the scrollbar. |
| Methods inherited from class controlP5.ControlGroup |
|---|
activateEvent, addCloseButton, arrayValue, getBackgroundHeight, hideBar, isBarVisible, mousePressed, removeCloseButton, setArrayValue, setBackgroundColor, setBackgroundHeight, setBarHeight, showBar, stringValue, toString, value |
| Methods inherited from class controlP5.ControllerGroup |
|---|
absolutePosition, add, addCanvas, addDrawable, captionLabel, close, color, continuousUpdateEvents, controller, disableCollapse, draw, enableCollapse, getAsXML, getColor, getHeight, getPickingColor, getTab, getWidth, getWindow, hide, id, init, isCollapse, isMoveable, isOpen, isUpdate, isVisible, isXMLsavable, keyEvent, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, name, open, parent, position, remove, remove, remove, removeCanvas, setGroup, setGroup, setId, setLabel, setMousePressed, setMoveable, setOpen, setPosition, setTab, setTab, setTab, setUpdate, setVisible, show, update, updateAbsolutePosition, updateEvents, updateInternalEvents, valueLabel |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Method Detail |
|---|
public void hideScrollbar()
public void showScrollbar()
public boolean isScrollbarVisible()
public void scroll(float theValue)
theValue - public void setItemHeight(int theHeight)
theHeight - public ListBox setHeight(int theHeight)
setHeight in class ControllerGrouptheHeight - public ListBox setWidth(int theWidth)
setWidth in class ControllerGroup
public ListBoxItem addItem(java.lang.String theName,
int theValue)
theName - StringtheValue - int#removeItem(String,int)public void removeItem(java.lang.String theItemName)
theItemName - StringaddItem(String,int)public ListBoxItem item(int theIndex)
theIndex -
public ListBoxItem item(java.lang.String theItemName)
theItemName -
public void controlEvent(ControlEvent theEvent)
ControlListener
controlEvent in interface ControlListenercontrolEvent in class ControlGrouptheEvent - ControlEvent
Controllerpublic void actAsPulldownMenu(boolean theValue)
theValue - controlP5.PulldownMenupublic void clear()
public void setColorActive(int theColor)
setColorActive in interface ControllerInterfacesetColorActive in class ControllerGrouptheColor - intpublic void setColorForeground(int theColor)
setColorForeground in interface ControllerInterfacesetColorForeground in class ControllerGrouptheColor - intpublic void setColorBackground(int theColor)
setColorBackground in interface ControllerInterfacesetColorBackground in class ControllerGrouptheColor - intpublic void setColorLabel(int theColor)
setColorLabel in interface ControllerInterfacesetColorLabel in class ControllerGrouptheColor - intpublic void setColorValue(int theColor)
setColorValue in interface ControllerInterfacesetColorValue in class ControllerGrouptheColor - intpublic void addToXMLElement(ControlP5XMLElement theElement)
addToXMLElement in interface ControllerInterfaceaddToXMLElement in class ControlGrouptheElement - ControlP5XMLElement
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||